using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.DAL.DAL.Business;
using XQ.RequestOfficeSupplies.DAL.Model.Business;
using XQ.RequestOfficeSupplies.DAL.Model;
using XQ.RequestOfficeSupplies.DAL.Models;
using XQ.RequestOfficeSupplies.DAL;

namespace XQ.RequestOfficeSupplies.BLL.Business
{
    public class OfficeSuppliesBLL
    {
        OfficeSuppliesDal officeSuppliesDal = new OfficeSuppliesDal();

        public List<OfficeSuppliesReturnModel> GetList(OfficeSuppliesSearchModel ssm, Pagination page, TokenModel token)
        {
            return officeSuppliesDal.GetList(ssm, page, token);
        }

        public Guid SaveOfficeSupplies(OfficeSupplies officeSupplies, TokenModel token)
        {
            Guid OfficeSuppliesID = officeSupplies.id;
            bool isSuccess = false;
            DateTime curTime = DateTime.Now;
            if (officeSupplies != null && officeSupplies.id != Guid.Empty)
            {
                //修改
                officeSupplies.updateTime = curTime;
                officeSupplies.updateUserID = token.UID;
                isSuccess = officeSuppliesDal.UpdateModel(officeSupplies) > 0;

            }
            else
            {
                //新增
                officeSupplies.id = Guid.NewGuid();
                officeSupplies.addTime = curTime;
                officeSupplies.addUserID = token.UID;
                OfficeSupplies officeSuppliesInfo = officeSuppliesDal.AddModel(officeSupplies);
                OfficeSuppliesID = officeSuppliesInfo.id;

            }

            return OfficeSuppliesID;
        }

        public OfficeSuppliesReturnModel GetOfficeSuppliesByID(Guid id)
        {
            OfficeSuppliesReturnModel officeSuppliesModel = new OfficeSuppliesReturnModel();
            OfficeSupplies officeSupplies = officeSuppliesDal.FindModel(c => c.id == id);
            officeSuppliesModel = ClassHelper.ParentCopyToChild<OfficeSupplies, OfficeSuppliesReturnModel>(officeSupplies);

            return officeSuppliesModel;
        }


        public int DeleteByIds(List<Guid> ids)
        {
            return officeSuppliesDal.DeleteModel(c => ids.Contains(c.id));
        }
    }
}
